<!--
 * @Author: 杨湲 yy7072@qq.com
 * @Date: 2025-09-11 16:31:18
 * @LastEditors: 杨湲 yy7072@qq.com
 * @LastEditTime: 2025-09-16 10:40:08
 * @FilePath: \大三上实训\city\src\pages\components(1)\Left1.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
        <Title :title="title"></Title>
        {{ed}}
        <div ref="left1" style="height: 150px;margin-top:10px;"></div>

    </div>
</template>
<script>
import { Line } from '@antv/g2plot';
import {get} from '@/utils/request';
import moment from 'moment';
import {mapState} from 'vuex';
export default {
    data() {
        return {
            title: '实时温度曲线',
            params:{
                page:1,
                pageSize:100
            },
            tempData:[],
            line:null
        }
    },
    computed:{
        ...mapState(['ed'])
    },
    watch:{
        ed:{
            handler(n,o){
                this.params.engineer_id = n.engineer_id;
                this.params.device_id = n.device_id;
                this.getTempData();
                this.line.changeData(this.tempData);
                
            },
            deep:true
        }

    },
    methods: {
        loadLine() {
            this.line = new Line(this.$refs.left1, {
                data:this.tempData,
                xField: 'insert_time',
                yField: 'temperature',
                xAxis: {
                    lable: {
                        rotate: -45,
                        style: {
                            fill: "white",
                            fontSize: 20
                        }
                    }

                },
                yAxis: {
                    lable: {
                        style: {
                            fill: "white",
                            fontSize: 20
                        }
                    }

                },
                label: {
                    style: {
                        fill: 'white',
                        fontSize: 20
                    }
                },
                point: {
                    size: 5,
                    shape: 'circle',
                    style: {
                        fill: 'pink',
                        stroke: '#5B8FF9',
                        lineWidth: 2,
                    },
                },
                smooth:true,
                animation: {
                    appear: {
                        animation: 'wave-in',
                        duration: 5000,
                    },
                },
                tooltip: { showMarkers: false, 
                    domStyles:{
                        "g2--tooltip":{
                            background:'#147',
                            color:"white",
                            fontSize:20
                        }
                    }
                },
                state: {
                    active: {
                        style: {
                            shadowBlur: 4,
                            stroke: '#000',
                            fill: 'red',
                        },
                    },
                },
                interactions: [{ type: 'marker-active' }],
            });

            this.line.render();
        },
        async getTempData(){
            let res = await get('/dashboard/pageQueryTodayData',this.params);
            // console.log(res,"获取响应");
            let temp = [];
            res.data.list.forEach((item,index,arr)=>{
                arr[0].temperature = 15.4;
                item.insert_time = moment(item.insert_time).format("HH:mm");
                if(index%10==0){
                  temp.push(arr[index])
                }
            });
            
            this.tempData = temp;
        }
    },
    async mounted() {
        await this.getTempData();
        this.loadLine();
    }
}
</script>
<style lang="less" scoped></style>